home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / err.cal < prev    next >
Text File  |  1995-03-23  |  8KB  |  502 lines

  1. Article 4720 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!mentor.cc.purdue.edu!purdue!news.cs.indiana.edu!news.nd.edu!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!csn!spot.Colorado.EDU!frechett
  3. From: frechett@spot.Colorado.EDU (-=Runaway Daemon=-)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: Operations with imprecise numbers.
  6. Keywords: errors
  7. Message-ID: <1991Mar3.090111.26666@csn.org>
  8. Date: 3 Mar 91 09:01:11 GMT
  9. Sender: news@csn.org (news)
  10. Organization: University of Colorado, Boulder
  11. Lines: 487
  12.  
  13. I just picked up these routines from the hpbbs.  Unfortunately, I downloaded
  14. them straight from the bbs into the calc so I don't have the message header to
  15. go with it, but I  see it down in the code.. (John A. Kyle)  This is a set of
  16. routines to deal with numbers like 2+-.5 or 3.056 +- .67 when doing the
  17. operations + - * / and ^.  Those operations are treated as absolute errors so
  18. that 2.0 +- .5 + 3.0 +-.5 will result in 6.0 +- 0.0.  
  19. Then there is an operation for dealing with stuff in a random fashion, with 90%
  20. assurance.  For an example, I could choose the EQ 'X + Y' and enter the numbers
  21. X = 2.0 dX = .5  Y= 3.0 dY= .5 and yeilds "To correct SIG.FIG's 5.0+-0.7"
  22. and the real result 5.0+-0.707106781187.  
  23.  
  24. For anyone with a physics class that requires any sort of error analysis of the
  25. data, this set of programs is a MUST.  The routines are completely idiot proof
  26. as they will tell you what to do if you don't have the right data.  Just
  27. download this directory and when it it, hit CST and then INTRO.  That will get
  28. you started.. I have found no problems in it yet.
  29.  
  30.         ian
  31.  
  32. --
  33. -=Runaway Daemon
  34. ----- X1DX --------------------------------------------
  35. %%HP: T(3)A(D)F(.);
  36. DIR
  37.   WORK
  38.     DIR
  39.       WIPE
  40.         \<< 'WIPE'
  41. DUP RCL CLVAR SWAP
  42. STO
  43.         \>>
  44.     END
  45.   X\177dX
  46.     \<<
  47. "Press left-shifted
  48. menu key for HELP"
  49. CLLCD 1 DISP 1
  50. FREEZE { { "INTRO"
  51. {
  52.       \<< IN
  53.       \>> } } { " + "
  54. {
  55.       \<< ADD
  56.       \>>
  57.       \<< IN.A
  58.       \>> } } { " - "
  59. {
  60.       \<< SUBT
  61.       \>>
  62.       \<< IN.S
  63.       \>> } } { " * "
  64. {
  65.       \<< MUL
  66.       \>>
  67.       \<< IN.M
  68.       \>> } } { " / "
  69. {
  70.       \<< DIV
  71.       \>>
  72.       \<< IN.D
  73.       \>> } } { " ^ "
  74. {
  75.       \<< PWR
  76.       \>>
  77.       \<< IN.P
  78.       \>> } } { "\|^\|v"
  79. {
  80.       \<< SWP2
  81.       \>>
  82.       \<< IN.SW
  83.       \>> } } {
  84. "f(x)" {
  85.       \<< RANDM
  86.       \>>
  87.       \<< IN.R
  88.       \>> } } { "\-> %"
  89. {
  90.       \<< P.UNC
  91.       \>>
  92.       \<< IN.%
  93.       \>> } } {
  94. "SIGFIG" {
  95.       \<< SIGFIG
  96.       \>>
  97.       \<< IN.SI
  98.       \>> } } } MENU
  99.     \>>
  100.   IN
  101.     \<<
  102. "
  103.   UNCERTAINTY
  104.      CALCULATION
  105.             PROGRAM
  106.  
  107.       for the HP 48SX
  108. [\|v]"
  109. CLLCD 1 DISP 0 WAIT
  110. "Written for the public
  111. domain by
  112.  
  113.  John A. Kyle
  114.  
  115.        UBC 1991
  116. [\|v]              v 1.1"
  117. CLLCD 1 DISP 0 WAIT
  118. " Absolute     Random
  119.   error       error
  120. functions    function
  121. ---------    --------
  122. + - * / ^      f(x)
  123.  
  124. [\|v]"
  125. CLLCD 1 DISP 0 WAIT
  126. "The absolute functions
  127. calculate total error
  128. whereas the random
  129. function calculates a
  130. less pessimistic error
  131. with a 90% confidence
  132. [\|v]          level"
  133. CLLCD 1 DISP 0 WAIT
  134. "utilizing:
  135.  
  136.  Z=f(x,..)
  137.                    1/2
  138. dZ=[(\.df/\.dx)^2*dx^2+..]
  139.  
  140. [\|v]"
  141. CLLCD 1 DISP 0 WAIT
  142. "NOTE:
  143.  
  144.    Use 0 for dX when
  145.  X has no uncertainty
  146.  associated with it,
  147.  etc."
  148. CLLCD 1 DISP 0 WAIT
  149. 6 DROPN
  150.     \>>
  151.   IN.A
  152.     \<<
  153. "Enter like so..
  154.  
  155. (X\177dX) + (Y\177dY)
  156.                 4:   X
  157.         \->       3:  dX
  158.                 2:   Y
  159.                 1:  dY"
  160. CLLCD 1 DISP 7
  161. FREEZE
  162.     \>>
  163.   IN.S
  164.     \<<
  165. "Enter like so..
  166.  
  167. (X\177dX) - (Y\177dY)
  168.                 4:   X
  169.         \->       3:  dX
  170.                 2:   Y
  171.                 1:  dY"
  172. CLLCD 1 DISP 7
  173. FREEZE
  174.     \>>
  175.   IN.M
  176.     \<<
  177. "Enter like so..
  178.  
  179. (X\177dX) * (Y\177dY)
  180.                 4:   X
  181.         \->       3:  dX
  182.                 2:   Y
  183.                 1:  dY"
  184. CLLCD 1 DISP 7
  185. FREEZE
  186.     \>>
  187.   IN.D
  188.     \<<
  189. "Enter like so..
  190.  
  191. (X\177dX) / (Y\177dY)
  192.                 4:   X
  193.         \->       3:  dX
  194.                 2:   Y
  195.                 1:  dY"
  196. CLLCD 1 DISP 7
  197. FREEZE
  198.     \>>
  199.   IN.P
  200.     \<<
  201. "Enter like so..
  202.       
  203.          x 
  204.    (Y\177dY)          
  205.                 3:   Y
  206.        \->        2:  dY
  207.                 1:   x"
  208. CLLCD 1 DISP 7
  209. FREEZE
  210.     \>>
  211.   IN.R
  212.     \<<
  213. "
  214.  Use EQUATION WRITER
  215. to enter symbolic
  216. expression..
  217.  
  218. then press f(x) key
  219. and follow prompts."
  220. CLLCD 1 DISP 7
  221. FREEZE
  222.     \>>
  223.   IN.SW
  224.     \<<
  225. "Rotates levels 1&2 
  226. with 3&4..
  227.  
  228. 4:   X          4:   Y
  229. 3:  dX   \->      3:  dY
  230. 2:   Y          2:   X
  231. 1:  dY          1:  dX"
  232. CLLCD 1 DISP 7
  233. FREEZE
  234.     \>>
  235.   IN.%
  236.     \<<
  237. "
  238.   Utility to convert 
  239.   from absolute to 
  240.   % uncertainty
  241.  
  242. ie. X\177dX  \->  X\177dX%"
  243. CLLCD 1 DISP 7
  244. FREEZE
  245.     \>>
  246.   IN.SI
  247.     \<<
  248. "
  249.    Utility to display
  250.  X\177dX with the correct
  251.  significant figures
  252.  as determined by the
  253.  uncertainty.
  254.  
  255. "
  256. CLLCD 1 DISP 7
  257. FREEZE
  258.     \>>
  259.   PRESERVE
  260.     \<< RCLF \-> f
  261.       \<< EVAL f STOF
  262.       \>>
  263.     \>>
  264.   CST { { "INTRO" {
  265.     \<< IN
  266.     \>> } } { " + " {
  267.     \<< ADD
  268.     \>>
  269.     \<< IN.A
  270.     \>> } } { " - " {
  271.     \<< SUBT
  272.     \>>
  273.     \<< IN.S
  274.     \>> } } { " * " {
  275.     \<< MUL
  276.     \>>
  277.     \<< IN.M
  278.     \>> } } { " / " {
  279.     \<< DIV
  280.     \>>
  281.     \<< IN.D
  282.     \>> } } { " ^ " {
  283.     \<< PWR
  284.     \>>
  285.     \<< IN.P
  286.     \>> } } { "\|^\|v" {
  287.     \<< SWP2
  288.     \>>
  289.     \<< IN.SW
  290.     \>> } } { "f(x)"
  291. {
  292.     \<< RANDM
  293.     \>>
  294.     \<< IN.R
  295.     \>> } } { "\-> %" {
  296.     \<< P.UNC
  297.     \>>
  298.     \<< IN.%
  299.     \>> } } {
  300. "SIGFIG" {
  301.     \<< SIGFIG
  302.     \>>
  303.     \<< IN.SI
  304.     \>> } } }
  305.   SUBT
  306.     \<<
  307.       IFERR \-> x dx
  308. y dy
  309.         \<< x y - 'Z'
  310. \->TAG dx dy + 'dZ'
  311. \->TAG SIGFIG
  312.         \>>
  313.       THEN IN.S
  314.       END
  315.     \>>
  316.   MUL
  317.     \<<
  318.       IFERR \-> x dx
  319. y dy
  320.         \<< x y * 'Z'
  321. \->TAG dx y * x dy *
  322. + 'dZ' \->TAG SIGFIG
  323.         \>>
  324.       THEN IN.M
  325.       END
  326.     \>>
  327.   DIV
  328.     \<<
  329.       IFERR \-> x dx
  330. y dy
  331.         \<< x y / 'Z'
  332. \->TAG dx y * x dy *
  333. + y 2 ^ / 'dZ' \->TAG
  334. SIGFIG
  335.         \>>
  336.       THEN IN.D
  337.       END
  338.     \>>
  339.   PWR
  340.     \<<
  341.       IFERR \-> y dy
  342. x
  343.         \<< y x ^ "Z"
  344. \->TAG dy x * y x 1 -
  345. ^ * "dZ" \->TAG
  346. SIGFIG
  347.         \>>
  348.       THEN IN.P
  349.       END
  350.     \>>
  351.   P.UNC
  352.     \<<
  353.       IFERR DUP2
  354. DTAG SWAP DTAG \-> dz
  355. z
  356.         \<< "  " 2
  357. FIX z \->STR " \177 "
  358. " % " dz z / 100 *
  359. ABS \->STR STD + + +
  360. + CLLCD 2 DISP
  361. "Percent Uncertainty"
  362. 1 DISP 1 FREEZE
  363.         \>>
  364.       THEN
  365. "
  366.  Requires entry 
  367. like so..
  368.  
  369.  Z\177dZ
  370.        \->    2:       Z
  371.             1:      dZ"
  372. CLLCD 1 DISP 7
  373. FREEZE
  374.       END
  375.     \>>
  376.   SIGFIG
  377.     \<<
  378.       IFERR DUP2
  379. DTAG SWAP DTAG \-> dx
  380. x
  381.         \<<
  382.           IF x TYPE
  383. 0 == x 0 \=/ AND dx
  384. TYPE 0 == dx 0 \=/
  385. AND AND
  386.           THEN "( "
  387. x XPON DUP dx XPON
  388. - FIX x DUP SIGN
  389. SWAP MANT * SWAP
  390. ALOG dx SWAP / "\177"
  391. SWAP " )E" + + + +
  392. STD x XPON +
  393. " To correct SIG.FIG's
  394. "
  395. SWAP + CLLCD 1 DISP
  396. 1 FREEZE
  397.           END
  398.         \>>
  399.       THEN
  400. "
  401.  Requires entry
  402. like so..
  403.    
  404.   Z\177dZ
  405.          \->    2:     Z
  406.               1:    dZ"
  407. CLLCD 1 DISP 7
  408. FREEZE
  409.       END
  410.     \>>
  411.   RANDM
  412.     \<<
  413.       IFERR DUP
  414.         \<< -2 SF -3
  415. CF
  416.           IF TYPE 9
  417. ==
  418.           THEN DUP
  419. { } 0 { } \-> equ
  420. dequ finlst ans
  421. varlst
  422.             \<<
  423. "stop"
  424.               WHILE
  425. dequ "stop" SAME
  426. NOT
  427.               REPEAT
  428. CASE dequ TYPE 9 ==
  429.   THEN dequ OBJ\->
  430. DROP2
  431.   END dequ TYPE 6
  432. ==
  433.   THEN varlst 1 3
  434. CF
  435.     IF varlst SIZE
  436.     THEN
  437.       DO GETI
  438.         IF dequ
  439. SAME
  440.         THEN 3 SF
  441.         END
  442.       UNTIL -64 FS?
  443.       END
  444.     END
  445.     IF 3 FC?
  446.     THEN dequ
  447. 'varlst' STO+
  448.     END DROP2
  449.   END
  450. END 'dequ' STO
  451.               END 3
  452. CF varlst 1
  453.               DO
  454. GETI \-> i
  455. \<<
  456. " Enter values for.."
  457. ": " i ":
  458. :d" i ":"
  459. + + + + { { 1 0 } V
  460. } + INPUT OBJ\-> equ
  461. i \.d * SQ 'ans' STO+
  462. DTAG i SWAP
  463. 'finlst' STO+
  464. 'finlst' STO+
  465. \>>
  466.               UNTIL
  467. -64 FS?
  468.               END
  469. DROP2 equ finlst |
  470. "Z" \->TAG ans finlst
  471. | \v/ "dZ" \->TAG
  472. SIGFIG
  473.             \>>
  474.           ELSE IN.R
  475.           END
  476.         \>> PRESERVE
  477.       THEN IN.R
  478.       END
  479.     \>>
  480.   SWP2
  481.     \<<
  482.       IFERR 4 ROLL
  483. 4 ROLL
  484.       THEN DROP
  485. IN.SW
  486.       END
  487.     \>>
  488.   ADD
  489.     \<<
  490.       IFERR \-> x dx
  491. y dy
  492.         \<< x y + 'Z'
  493. \->TAG dx dy + 'dZ'
  494. \->TAG SIGFIG
  495.         \>>
  496.       THEN IN.A
  497.       END
  498.     \>>
  499. END
  500.  
  501.  
  502.